package com.lwj.test.netty;

import static org.jboss.netty.channel.Channels.pipeline;

import java.nio.charset.Charset;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.jboss.netty.handler.codec.string.StringEncoder;

public class ClientPipelineFactory implements ChannelPipelineFactory
{
    public ChannelPipeline getPipeline() throws Exception
    {
        ChannelPipeline pipleline = pipeline();  
        pipleline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));  
        pipleline.addLast("frameEncode", new LengthFieldPrepender(4, false));
        pipleline.addLast("encode", new StringEncoder(Charset.forName("GBK")));  
        pipleline.addLast("decode", new StringDecoder(Charset.forName("GBK")));  
        //pipleline.addLast("handler", new ClientHandler());  
        return pipleline;  
    }
}